/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kivuli.rn;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import kivuli.entidade.Projeto;
import kivuli.persistencia.Persistencia;

/**
 *
 * @author bpmlab
 */
public class PersistenciaRN {

    public static void salvar(Projeto projeto) {
        JFileChooser chooser = new JFileChooser("mikaelLindo");
        chooser.setFileFilter(new FileNameExtensionFilter("*.kv", "kv"));
        chooser.setMultiSelectionEnabled(false);
        int retorno = chooser.showSaveDialog(null);
        if (retorno == JFileChooser.APPROVE_OPTION) {
            String path = chooser.getSelectedFile().getPath();
            if (!path.endsWith(".kv")) {
                path = chooser.getSelectedFile().getPath() + ".kv";
            }
            File file = new File(path);
            Persistencia.salvar(file, projeto);
        }
    }

    public static Projeto abrir() {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("*.kv", "kv"));
        chooser.setMultiSelectionEnabled(false);
        int retorno = chooser.showOpenDialog(null);
        if (retorno == JFileChooser.APPROVE_OPTION) {
            return Persistencia.abrir(chooser.getSelectedFile());
        } else {
            return null;
        }
    }

}
